set more 1

/*
File:	cepr_basic_idvar.do
Date:	Nov 21, 2006
	Feb 15, 2008
	Feb 10, 2009
	Jan 4, 2010
	Feb 22, 2011
	Jan 3, 2012
	Jan 3, 2013
	Nov 26, 2013
	Mar 12, 2015, CEPR ORG Version 2.0
	Apr  1, 2015, CEPR ORG Version 2.0.1
	March 1, 2016, CEPR ORG Version 2.1
	Oct 12, 2016, CEPR ORG Version 2.1.1
	Feb 9, 2017, CEPR ORG Version 2.2
	Apr 21, 2017, CEPR ORG Version 2.2.1
	Apr 10, 2018, CEPR ORG Version 2.3
	Mar 22, 2019, CEPR ORG Version 2.4
	Jul 24, 2019, CEPR ORG Version 2.4.1
	Feb 05, 2020, CEPR ORG Version 2.5
	
Desc:	Creates consistent household and personal identifiers and weights
	for CEPR consistent extract of Basic CPS
Note:	See copyright notice at end of program.
*/

/* note: any pre-1994 data processing is not yet correct;
         use only to process data from 1994 forward
*/

/* Determine data year */
local year=year in 1
lab var year "Year"

/* Month of interview */

gen byte month=.

if `year'==1991 {
replace month=hdmonth
replace month=. if hdmonth<1
}
if 1994<=`year' & `year'<=2020 {
replace month=hrmonth
replace month=. if hrmonth<1
}
lab var month "Month"
notes month: CPS: hrmonth

/* Month in sample */

gen byte minsamp=.

if `year'==1991 {
replace minsamp=hdmis
replace minsamp=. if hdmis<1
}
if 1994<=`year' & `year'<=2020 {
replace minsamp=hrmis
replace minsamp=. if hrmis<1
}
lab var minsamp "Month in sample"
notes minsamp: CPS: hrmis

/* Household identification number: hhid */

if `year'==1991 {
rename hdid hhid /* use rename not replace because string size changes */
}
if 1994<=`year' & `year'<=2020 {
rename hrhhid hhid  /* use rename not replace because string size changes */
}
lab var hhid "Household ID"
notes hhid: Unique to address, not household 
notes hhid: From May 2004-, concatenate hhid2 with hhid to uniquely identify HH
notes hhid: CPS: hrhhid

/* Household identifier 2: hhid 2 */

if `year'<=2003 {
gen byte hhid2=.
}
if 2004==`year' {
* keep the variable name same for Jan-April
gen str5 hhid2=hrhhid2
}
if 2005<=`year' & `year'<=2020 {
rename hrhhid2 hhid2
}
lab var hhid2 "Household ID Part 2"
notes hhid2: Unique to address, not household
notes hhid2: Available May 2004- only
notes hhid2: From May 2004-, concatenate hhid2 with hhid to uniquely identify HH
notes hhid2: CPS: hrhhid2

/* Household sample ID: hrsample */

if 1994<=`year' & `year'<=2003 {
* keep the variable name same
}
if `year'==2004 {
* keep the variable name same for Jan-April
replace hrsample = substr(hhid2,1,2) if (5<=month & month<=12)
}
if 2005<=`year' & `year'<=2020 {
gen str2 hrsample=substr(hhid2,1,2)
}

lab var hrsample "Household sample ID"
notes hrsample: From May 2004 on, this is a subset of hrhhid2 (hhid2)
notes hrsample: CPS: hrsample (1994-April 2004), hrhhid2 (May 2004-on)
notes hrsample: Available 1994- only

/* Household serial suffix: hrsersuf */

if 1994<=`year' & `year'<=2003 {
* keep the variable name same
}
if `year'==2004 {
* keep the variable name same for Jan-April
replace hrsersuf = substr(hhid2,3,2) if (5<=month & month<=12)
}
if 2005<=`year' & `year'<=2020 {
gen str2 hrsersuf = substr(hhid2,3,2)
}

lab var hrsersuf "Household serial suffix"
notes hrsersuf: Use to differentiate HH with same hhid
notes hrsersuf: From May 2004 on, this is a subset of hrhhid2 (hhid2)
notes hrsersuf: Available 1994- only
notes hrsersuf: CPS: hrsersuf (1994-April 2004), hrhhid2 (May 2004-on)

/* Household replacement number hhnum */

if `year'==1991 {
gen hhnum=.
replace hhnum=hdhhnum
replace hhnum=. if hdhhnum<0
}
if 1994<=`year' & `year'<=2003 {
gen hhnum=.
replace hhnum=huhhnum
replace hhnum=. if huhhnum<0
}
if `year'==2004 {
* keep the variable name same for Jan-April
tostring huhhnum, replace
replace huhhnum = substr(hhid2,-1,1) if (5<=month & month<=12)
rename huhhnum hhnum
}
if 2005<=`year' & `year'<=2020 {
gen str1 huhhnum = substr(hhid2,-1,1)
rename huhhnum hhnum
}

lab var hhnum "Household counter"
notes hhnum: Increments by 1 for each new household at hhid address
notes hhnum: From May 2004 on, this is a subset of hrhhid2 (hhid2)
notes hhnum: CPS: h-hhnum, huhhnum (1994-April 2004), hrhhid2 (May 2004-on)

/* Household longitudinal link: hrlonglk  */

if `year'<1994 {
gen hrlonglk=. /* not available before 1994 */ 
}
if 1994<=`year' & `year'<=2020 {
* use hrlonglk variable from Basic CPS
}
lab var hrlonglk "Longitudinal link"
lab def link 0 "New or Replacement" 2 "Continuing" 3 "MIS 5"
lab val hrlonglk link
notes hrlonglk: Longitudinal link is month-to-month, not year to year
notes hrlonglk: Available 1994-on
notes hrlonglk: CPS: hrlonglk

/* Person number: lineno */

gen lineno=.

if `year'==1991 {
replace lineno=adlineno
replace lineno=. if adlineno<0
}
if 1994<=`year' & `year'<=2020 {
replace lineno=pulineno
replace lineno=. if pulineno<0
}
lab var lineno "Person number"
notes lineno: Person line number within household
notes lineno: CPS: pulineno

/* Weights */

	/* Final weight */
	
gen fnlwgt=.

if `year'==1991 {
replace fnlwgt=adfnlwgt
replace fnlwgt=. if adfnlwgt<=0
}
if 1994<=`year' & `year'<=2020 {
replace fnlwgt=pwsswgt
replace fnlwgt=. if pwsswgt<=0
}
lab var fnlwgt "Final weight"
notes fnlwgt: For most tabulations
notes fnlwgt: Controlled to independent estimates for (1) states; /*
*/ (2) origin, sex, and age; and (3) age, race, and sex
notes fnlwgt: CPS: pwsswgt, adfnlwgt

	/* ORG weight */
	
gen orgwgt=.

if `year'==1991 {
replace orgwgt=adernlwt
replace orgwgt=. if adernlwt<=0
}
if 1994<=`year' & `year'<=2020 {
replace orgwgt=pworwgt
replace orgwgt=. if pworwgt<=0
}
lab var orgwgt "Earnings weight"
notes orgwgt: Only for information collected only in ORG
notes orgwgt: Sum to civilian, non-institutional population in each month
notes orgwgt: To obtain approximate US population with full year of data, /*
*/ divide orgwgt by 12
notes orgwgt: CPS: pworwgt, adernlwt

	/* Longitudinal weight */

gen lonwgt=.

if 1994<=`year' & `year'<=2020 {
replace lonwgt=pwlgwgt
replace lonwgt=. if pwlgwgt<=0
}
lab var lonwgt "Longitudinal weight"
notes lonwgt: Only for adult records matched across CPS from month to month
notes lonwgt: Used for gross flow analysis
notes lonwgt: Available 94-on
notes lonwgt: CPS: pwlgwgt

	/* Family weight */
	
gen famwgt=.

if `year'==1991 {
replace famwgt=adfamwgt
replace famwgt=. if adfamwgt<=0
}
if 1994<=`year' & `year'<=2020 {
replace famwgt=pwfmwgt
replace famwgt=. if pwfmwgt<=0
}
lab var famwgt "Family weight"
notes famwgt: Only for tallying family characteristics
notes famwgt: Sum to civilian, non-institutional population in each month
notes famwgt: To obtain approximate US population with full year of data, /*
*/ divide orgwgt by 12
notes famwgt: Available 1994-on
notes famwgt: CPS: pwfmwgt

/* 
Copyright 2020 CEPR and John Schmitt

This file is part of the cepr_org_master.do program. This file and all
programs referenced in it are free software. You can redistribute the
program or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
USA.
*/
